package com.ttc.group2.videochat.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;

import com.ttc.group2.videochat.R;
import com.ttc.group2.videochat.utils.ViewUtil;

public class MessageArea extends LinearLayout {
	private ImageButton imgIconPicker;
	private ImageButton imgSend;
	private EditText edtTypeMessage;

	public MessageArea(Context context) {
		super(context);
		if (isInEditMode()) {
			return;
		}
		init();
	}

	public MessageArea(Context context, AttributeSet attrs) {
		super(context, attrs);
		if (isInEditMode()) {
			return;
		}
		init();
	}

	public MessageArea(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		if (isInEditMode()) {
			return;
		}
		init();
	}

	private void init() {
		LayoutInflater.from(getContext()).inflate(R.layout.message_area_input,
				this);
		imgIconPicker = (ImageButton) ViewUtil.findViewById(imgIconPicker,
				R.id.chat_emotion_picker);
		imgSend = (ImageButton) ViewUtil.findViewById(imgSend,
				R.id.chat_item_send);
		edtTypeMessage = (EditText) ViewUtil.findViewById(edtTypeMessage,
				R.id.chat_input_message);

		View[] arrayOfView = new View[2];
		arrayOfView[0] = this.imgIconPicker;
		arrayOfView[1] = this.imgSend;
		ViewUtil.setAttrView(arrayOfView);
		refreshSendButton();
	}

	private void refreshSendButton() {
		if (this.edtTypeMessage.getText().length() > 0) {
			this.imgSend.setEnabled(true);
		} else {
			this.imgSend.setEnabled(false);
		}
	}

}
